package com.letou.ls.uitl;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class DialogUtils {

	private static AlertDialog alertDialog;

	/**
	 * 提示内容！。
	 */
	public static void showDialog(Context context, String title, String message) {

		if (alertDialog != null && alertDialog.isShowing()) {
			alertDialog.dismiss();
			alertDialog.cancel();
		}
		alertDialog = new AlertDialog.Builder(context).setTitle(title).setMessage(message)
				.setPositiveButton("取消", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				}).create();
		if (((Activity) context).isFinishing()) {
			return;
		} else {
			alertDialog.show();
		}
	}

	public static void showDialog(Context context, String title, String message, OnClickListener okListener,
			OnClickListener cacelListener) {
		if (alertDialog != null && alertDialog.isShowing()) {
			alertDialog.dismiss();
			alertDialog.cancel();
		}
		alertDialog = new AlertDialog.Builder(context).setTitle(title).setMessage(message)
				.setPositiveButton("确定", okListener).setNegativeButton("取消", cacelListener).create();
		if (((Activity) context).isFinishing()) {
			return;
		} else {
			alertDialog.show();
		}
	}

	public static void showDialog(Context context, String title, String message, OnClickListener okListener) {

		if (alertDialog != null && alertDialog.isShowing()) {
			alertDialog.dismiss();
			alertDialog.cancel();
		}
		alertDialog = new AlertDialog.Builder(context).setTitle(title).setMessage(message)
				.setPositiveButton("确定", okListener).setNegativeButton("取消", new OnClickListener() {

					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						// TODO Auto-generated method stub
						arg0.dismiss();

					}
				}).create();
		if (((Activity) context).isFinishing()) {
			return;
		} else {
			alertDialog.show();
		}
	}
}
